using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for ActionsAdaptor.
	/// </summary>
	public class ActionsAdaptor : Adaptor, IRefreshable
	{
    private ActionCollection actions;
		public ActionsAdaptor(ActionCollection actions)
		{
      this.actions = actions;
		}

    public override string Text
    {
      get
      {
        return "Actions (" + actions.Count + ")";
      }
    }

    public override void AddChildren(TreeNode node)
    {
      foreach (Action action in actions)
      {
        TreeNode childNode = TreeNodeFactory.CreateTreeNode(new ActionAdaptor(action));
        node.Nodes.Add(childNode);
      }  
    }

    public override int ImageIndex
    {
      get
      {
        return 14;
      }
    }

    public override Control GetRenderer()
    {
      ActionsControl control = new ActionsControl();
      control.LoadActions(actions);
      control.RefreshRequired += new EventHandler(TriggerRefreshRequired);
      return control;
    }

    public override object Object
    {
      get
      {
        return actions;
      }
    }

    #region IRefreshable Members

    public void Refresh()
    {
      actions.Refresh();
    }

    #endregion
  }
}
